<?php

namespace App\Http\Controllers\Web;

use App\Models\Company;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use function PHPUnit\Framework\isEmpty;

class CompanyController extends Controller
{
    public function index()
    {
        $query = Company::query()->first();

        return $this->success($query);
    }

    public function requestData(Request $request)
    {
        $requestData = $this->validate($request, [
            'name' => 'required',
            'name_en' => 'nullable',
            'weixin' => 'required',
            'phone' => "required",
            'qq' => 'required',
            'sina_weibo' => 'required',
            'logo_url' => "required",
            'footprint' => 'required',
            'production_workshop' => 'required',
            'laboratory' => "required",
            'writing_ink' => 'required',
            'inkjet_printing' => "required",
            'introduction' => 'required',
            'introduction_en' => 'nullable',
            'address' => 'required',
        ]);
        return $requestData;
    }

    public function update(Request $request)
    {
        $requestData = $this->requestData($request);
        $company = Company::query()->first();
        if(!$company) {
            $company = new Company();
        }
        $company->fill($requestData);
        $company->save();
        return $this->success($requestData);
    }
}
